<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__STATIC__/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="__STATIC__/css/public.css" media="all">
</head>

<body>
    <div class="layuimini-container">
        <div class="layuimini-main">

            <fieldset class="table-search-fieldset">
                <legend>搜索信息</legend>
                <div style="margin: 10px 10px 10px 10px">
                    <form class="layui-form layui-form-pane" action="">
                        <div class="layui-form-item">

                            <div class="layui-inline">
                                <div class="layui-input-inline">
                                    <select name="modules" lay-verify="required" lay-search="" id="modules">
                                        <option value="">选择搜索的类型</option>
                                        <option value="job_number">工号</option>
                                        <option value="name">姓名</option>
                                        <option value="sex">性别</option>
                                        <option value="company">生日</option>
                                        <option value="birthday">生日</option>
                                        <option value="working_hours">参加工作时间</option>
                                        <option value="highest_education">最高学历</option>
                                        <option value="title">职称</option>
                                        <option value="job_category">任职类别</option>
                                        <option value="current_administrative_position">当前行政职务</option>
                                        <option value="current_administrative_position_level">当前行政职务级别</option>
                                        <option value="tenure">任职时间</option>
                                        <option value="part_time_administrative_position">兼职行政职务</option>
                                        <option value="part_time_administrative_position_level">兼职行政职务级别</option>
                                        <option value="part_time_company">兼职单位</option>
                                        <option value="part_time_tenure">兼职任职时间</option>
                                        <option value="previous_administrative_position">上任行政职务</option>
                                        <option value="previous_administrative_position_level">上任行政职务级别</option>
                                        <option value="previous_tenure">上任任职时间</option>
                                        <option value="idcard_number">身份证号</option>
                                        <option value="contact_information">联系方式</option>
                                        <option value="bank_card_number">银行卡号</option>
                                        <option value="highest_academic_title">最高学历职称</option>
                                        <option value="starting_salary_time_of_the_current_year">当年起薪时间</option>
                                        <option value="stoping_salary_time_of_the_current_year">停发工资时间</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline">
                                <div class="layui-input-inline">
                                    <input type="text" name="value" id="value" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <button type="submit" class="layui-btn layui-btn-primary" lay-submit
                                    lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                            </div>

                        </div>
                    </form>
                </div>
            </fieldset>

            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加 </button>
                    <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除选中
                    </button>
                </div>
            </script>

            <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

            <script type="text/html" id="currentTableBar">
                <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
                <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
            </script>

        </div>
    </div>
    <script src="__STATIC__/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script>
        layui.use(['form', 'table'], function () {
            var $ = layui.jquery,
                form = layui.form,
                table = layui.table;

            table.render({
                elem: '#currentTableId',
                url: "{:url('index/BaseInfo/getBaseinfo')}",
                toolbar: '#toolbarDemo',
                defaultToolbar: ['filter', 'exports', 'print', {
                    title: '提示',
                    layEvent: 'LAYTABLE_TIPS',
                    icon: 'layui-icon-tips'
                }],
                cols: [
                    [{
                            type: "checkbox",
                            width: 50
                        },
                        {
                            field: 'user_id',
                            width: 100,
                            title: '用户ID',
                            sort: true
                        },
                        {
                            field: 'job_number',
                            width: 150,
                            title: '工号',
                            sort: true
                        },
                        {
                            field: 'name',
                            width: 100,
                            title: '姓名'
                        },
                        {
                            field: 'sex',
                            width: 100,
                            title: '性别'
                        },
                        {
                            field: 'company',
                            width: 200,
                            title: '所在单位'
                        },
                        {
                            field: 'birthday',
                            width: 150,
                            title: '出生年月',
                        },
                        {
                            field: 'working_hours',
                            width: 150,
                            title: '参加工作时间',
                        },
                        {
                            field: 'highest_education',
                            title: '最高学历',
                            minWidth: 150
                        },
                        {
                            field: 'title',
                            width: 100,
                            title: '职称'
                        },
                        {
                            field: 'job_category',
                            width: 150,
                            title: '任职类别'
                        },
                        {
                            field: 'current_administrative_position',
                            width: 150,
                            title: '当前行政职务'
                        },
                        {
                            field: 'current_administrative_position_level',
                            width: 180,
                            title: '当前行政职务级别',
                            sort: true
                        },
                        {
                            field: 'tenure',
                            width: 135,
                            title: '任职时间',
                        },
                        {
                            field: 'part_time_administrative_position',
                            width: 150,
                            title: '兼职行政职务'
                        },
                        {
                            field: 'part_time_administrative_position_level',
                            width: 180,
                            title: '兼职行政职务级别',
                            sort: true
                        },
                        {
                            field: 'part_time_company',
                            width: 135,
                            title: '兼职单位'
                        },
                        {
                            field: 'part_time_tenure',
                            width: 135,
                            title: '兼职任职时间'
                        },
                        {
                            field: 'previous_administrative_position',
                            width: 150,
                            title: '上任行政职务'
                        },
                        {
                            field: 'previous_administrative_position_level',
                            width: 180,
                            title: '上任行政职务级别',
                            sort: true
                        },
                        {
                            field: 'previous_tenure',
                            width: 150,
                            title: '上任任职时间'
                        },
                        {
                            field: 'idcard_number',
                            width: 150,
                            title: '身份证号'
                        },
                        {
                            field: 'contact_information',
                            width: 150,
                            title: '联系方式'
                        },
                        {
                            field: 'bank_card_number',
                            width: 200,
                            title: '银行卡号'
                        },
                        {
                            field: 'highest_academic_title',
                            width: 150,
                            title: '最高学历职称'
                        },
                        {
                            field: 'starting_salary_time_of_the_current_year',
                            width: 150,
                            title: '当年起薪时间'
                        },
                        {
                            field: 'stoping_salary_time_of_the_current_year',
                            width: 150,
                            title: '停发工资时间',
                        },
                        {
                            title: '操作',
                            minWidth: 150,
                            toolbar: '#currentTableBar',
                            align: "center"
                        }
                    ]
                ],
                limits: [10, 15, 20, 25, 50, 100],
                limit: 15,
                page: true,
                skin: 'line'
            });

            // 监听搜索操作
            form.on('submit(data-search-btn)', function (data) {


                //执行搜索重载
                table.reload('currentTableId', {
                    page: {
                        curr: 1
                    },
                    where: {
                        value: $('#value').val(),
                        modules: $('#modules').val()
                    }
                }, 'data');

                return false;
            });

            /**
             * toolbar监听事件
             */
            table.on('toolbar(currentTableFilter)', function (obj) {
                    if (obj.event === 'add') { // 监听添加操作
                        var index = layer.open({
                            title: '添加窗口',
                            type: 2,
                            shade: 0.2,
                            maxmin: true,
                            shadeClose: true,
                            area: ['90%', '90%'],
                            content: "{:url('index/BaseInfo/add')}",
                        });
                        $(window).on("resize", function () {
                            layer.full(index);
                        });
                    } else if (obj.event === 'delete') { // 监听删除操作
                        layer.confirm('真的删除这些吗', function (index) {
                                var checkStatus = table.checkStatus('currentTableId'),
                                    data = checkStatus.data;
                                var ids = [];
                                for (var i = 0; i < data.length; i++) {
                                    ids.push(checkStatus.data[i].user_id)
                                }
                                $.ajax({
                                        data: {
                                            "id": ids
                                        },
                                        url: "{:url('index/BaseInfo/removeselected')}",
                                        type: 'post',
                                        success: function (data) {
                                            if (data.code == 1) {
                                                layer.msg(data.msg);
                                                //执行搜索重载
                                                table.reload();
                                        } else {
                                            layer.msg(data.msg);
                                        }
                                    }
                                });
                            //执行搜索重载
                            table.reload('currentTableId', {
                                page: {
                                    curr: 1
                                }
                            }, 'data'); layer.close(index);
                        });
                }
            });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        }); table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                var index = layer.open({
                    title: '编辑窗口',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: "{:url('index/BaseInfo/edit')}?id=" + data.user_id,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'delete') {
                layer.confirm('真的删除行么', function (index) {
                    $.post("remove", "id=" + data.user_id, function (data) {
                        if (data.code == 1) {
                            layer.msg(data.msg);
                            table.reload();
                        } else {
                            layer.msg(data.msg);
                        }
                    });
                    obj.del();
                    layer.close(index);
                });
            }
        });

        });
    </script>

</body>

</html>